<%= flash_messages %>
<div class="box round">
	<div class="bbox round">
		<h1><%= t("ui.search_messages") %></h1>
		<div>
			<% form_tag msgsearch_path, :method => :get do %>
			<%= text_field_tag :q, params[:q] %>
			<%= submit_tag t("ui.search"), :name => nil  %>
			<% end %>
		</div>
	</div>
	<div class="bbox-pointer">&nbsp;</div>
  


	<div id='messages'>
		<div class="pagination"><%= will_paginate @messages %></div>
		
		<% @messages.each do |message| %>
		  
		  <%# FIXME: I don't know how to filter the messages in private convos with sphinx search without reindexing the database each time a convo troggles the private status %>
		  <% if message.conversation.private? %>
		    <% if logged_in? %>
		      <% next if !message.conversation.followed_by?(current_user) && current_user != message.conversation.owner %>
		    <% else %>
		      <% next %>
		    <%end%>
		  <% end %>
		  
		  <%# REFACTOR DRY: this markup is used in some places %>
    	<div class="message" id="<%= dom_id(message) %>">
    	  <div class="avatar"><%= link_to image_tag(message.user.gravatar_url, :width => 30, :height => 30, :class => "avatar", :alt => message.user.login), user_path(message.user),
    		:class => 'tip', 
    		:title =>  user_popup(message.user) %>
    		</div>
    		<div class="messagetext">

		  		<%= highlight mark_up(message), params[:q].split %>

    			<div class="meta">
    	      <span class="date quiet small">
    			  	<%= link_to message.time_pretty,
    			   conversation_message_path(message.conversation, message), :title => message.date_pretty_long %> -
    			  </span>
    			  <span class="username"><%=link_to h(message.user.login), user_path(message.user) %></span>
    			  <div class="messagelinks quiet small">
      			<% if logged_in? %>
      				<%= link_to_remote t("ui.report"), :url => report_conversation_message_path(message.conversation, message), :confirm => t("ui.reportconfirm") %>
      	      <%= link_to t("ui.spawn"), spawn_new_conversation_path(:message_id => message.id), :confirm => t("ui.spawnconfirm"), :method => :get %> <% #has to be the get in order for auth token to work %>
      			<% end %>
      			<%= link_to t("conversations.go_to_conversation"), conversation_path(message.conversation_id) %>
      		  </div>
          </div>
    		</div>
    		<div class="clear"></div>
    	</div>
    	
	  <% end %>

		<div class="pagination"><%= will_paginate @messages %></div>

	</div>
</div>

